<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            background-color: aqua;
            width: 400px;
            height: 200px;
            margin: auto;
        }
        p{
            padding-left: 25px;
            text-align: center;
        }
        h3{
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="box">
        <h3>随即问答</h3>
        <p>Who:</p>
        <button class="left">开始</button>
        <button class="right">结束</button>
    </div>
    <script>
        const arr=['三','四','五','张三','李四','王五','张','李','王']
        const p=document.querySelector('p')
        const btn1=document.querySelector('.left')
        const btn2=document.querySelector('.right')
        let time=0
        let random=0
        btn1.addEventListener('click',function(){
            time=setInterval(function(){
                const random=Math.floor(Math.random()*arr.length)
                p.innerHTML=arr[random]
            },100)
        if(arr.length===1){
            btn1.disabled='true'
            btn2.disabled='true'
            alert('只剩一个元素')
        }
        })
        btn2.addEventListener('click',function(){
            clearInterval(time)
            arr.splice(arr[random],1)
        })

        // btn1.addEventListener('click',function(){
        //         function set(){
        //     let rd=Math.floor(Math.random()*arr.length)
        //         console.log(arr[rd])
        // }
        // setInterval(set,500)
        // })
        // btn2.addEventListener('click',function(){
        //     let time=setInterval(function(){document.write('666<br>')},1000)
        // clearInterval(time)
        // console.log(time)
        // })
    </script>
</body>
</html>